package com.example.servlet;

import com.example.dao.NovelDao;
import com.example.domain.Novel;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
@WebServlet("/NovelTypeServlet")
public class NovelTypeServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
    {
        request.setCharacterEncoding("utf-8");
        String category = request.getParameter("category");
        NovelDao novelDao = new NovelDao();
        List<Novel> novelList = novelDao.getTotalCountByType(category);
        if(novelList.size()==0){
            request.setAttribute("msg","没有找到该类型小说！");
            request.getRequestDispatcher("category.jsp").forward(request,response);
            return;
        }
        request.setAttribute("novels",novelList);
        request.getRequestDispatcher("category.jsp").forward(request,response);
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
    {
        doGet(request,response);
    }
}
